<link rel="stylesheet" href="/resources/common/bootstrap-3.3.4/css/bootstrap.min.css" />
<link rel="stylesheet" href="/resources/frontend/css/style.css" />
<script type="text/javascript" src="/resources/common/js/iscroll.js"></script>
<style>
    body {
        background-color: #e5e5e5;
    }
    .bonus-list button{
        padding: 0px 8px;
        background-color: red;
        border: 1px solid red;
        color: #fff;
        border-radius: 6px;
    }
    .nav-tabs>li>a {
        margin-right: 0;
        border: none;
        text-align: center;
        color: #445;
    }
    .nav-tabs>li.active>a, .nav-tabs>li.active>a:focus, .nav-tabs>li.active>a:hover {
        color: #e82e2e;
        background-color: #fff;
        border: none;
        border-bottom: solid 2px #e82e2e;
    }
    .bonus-list {
        padding: 0 16px;
        background-color: #FFF;
        min-height: 400px;
    }
    .bonus-list li{
        padding: 8px 0;
        height: 55px;
        border-bottom: solid 1px #ddd;
        background-color: #FFF;
        list-style: none;
    }
    .nav-tabs>li>a {
        border-radius: 0;
        background-color: #FFF;
    }
    *{margin:0;padding:0;}
    html{font-size:10px}
    @media screen and (max-width: 320px) {html{font-size: 10px}}
    @media screen and (min-width:321px) and (max-width:375px){html{font-size:11px}}
    @media screen and (min-width:376px) and (max-width:414px){html{font-size:12px}}
    @media screen and (min-width:415px) and (max-width:639px){html{font-size:13px}}
    @media screen and (min-width:640px) and (max-width:719px){html{font-size:20px}}
    @media screen and (min-width:720px) and (max-width:749px){html{font-size:22.5px}}
    @media screen and (min-width:750px) and (max-width:799px){html{font-size:23.5px}}
    @media screen and (min-width:800px){html{font-size:25px}}
    @media screen and (max-width: 1000px) {
        img {
            max-width: 100%;
        }
    }

    #wrapper{
        width: 100%;
        position: absolute;
        left: 0;
        top: 17.5%;
        bottom: 4rem;
        /*overflow: hidden;*/
        z-index: 1;
    }

    .more{
        height: 4rem;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #333;
    }
    .pull_icon{
        width: 25px;
        height: 25px;
        background-image: url('/resources/frontend/images/pull.png');
        background-repeat: no-repeat;
        background-position: center;
        background-size: 25px;
        transition: all .5s;
    }
    .more span{
        padding-left: .5rem;
    }

    .scroller{
        background-color: #fff;
    }


    .more .flip{
        transform: rotate(180deg);
    }
    .loading{
        background-image: url('/resources/frontend/images/loading.png');
        background-repeat: no-repeat;
        background-position: center;
        background-size: 25px;
    }
    .more .loading{
        -webkit-transform: rotate(0deg) translateZ(0);
        -webkit-transition-duration: 0;
        -webkit-animation-name: loading;
        -webkit-animation-duration: 2s;
        -webkit-animation-iteration-count: infinite;
        -webkit-animation-timing-function: linear;
    }

    @-webkit-keyframes loading {
        from {
            -webkit-transform: rotate(0deg) translateZ(0);
        }
        to {
            -webkit-transform: rotate(360deg) translateZ(0);
        }
    }
    /* payment disp label */
    .discount-setup {
        background: none;
        text-align: center;
        box-shadow: none;
        border: none;
        margin: 50px auto 0 auto;
        width: 280px;
    }

    .discount-setup #sub-img {
        position: absolute;
        left: 50%;
        margin-left: -50px;
        top: 220px;
        width: 100px;
        height: 100px;
        border-radius: 5px;
        z-index: 9999;
    }
    .discount-setup .close {
        display: block;
        position: absolute;
        top: -20px;
        right: -17px;
        border: none;
        box-shadow: none;
        background: none;
        outline: none !important;
        color: #FFF;
        filter: alpha(opacity=70) !important;
        -moz-opacity: 0.7 !important;
        -khtml-opacity: 0.7 !important;
        opacity: 0.7 !important;
    }
    #text-des{
        position: absolute;
        width: 100%;
        text-align: center;
        left: 0px;
        top: 140px;
        font-size: 20px;
        color: #FBdfc9;
        font-weight: 600;
    }
    #jiantou{
        position: absolute;
        left: 72px;
        top: 165px;
        height: 40px;
        width: 20px;
    }
    .rotate{
        -webkit-animation: anim .4s infinite alternate;
        -ms-animation: anim .4s infinite alternate;
        animation: anim .4s infinite alternate;
    }
    .rotate_span{
        transform:rotate(25deg);
        -ms-transform:rotate(25deg); 	/* IE 9 */
        -moz-transform:rotate(25deg); 	/* Firefox */
        -webkit-transform:rotate(25deg); /* Safari 和 Chrome */
        -o-transform:rotate(25deg); 	/* Opera */
    }
    @-webkit-keyframes anim {
        from { -webkit-transform: rotateY(180deg); }
        to { -webkit-transform: rotateY(360deg); }
    }
    @-ms-keyframes anim {
        from { -ms-transform: rotateY(180deg); }
        to { -ms-transform: rotateY(360deg); }
    }
    @keyframes anim {
        from { transform: rotateY(180deg); }
        to { transform: rotateY(360deg); }
    }
    .rule_p{
        text-align: left;
    }
    #double-txt{
        /*border: 1px solid red;*/
        background-color: gold;
        width: 120px;
        height: 60px;
        margin: 0 auto;
        margin-top: 20px;
        font-size: 3rem;
        color: #7e6934;
        line-height: 20px;
        background: url("/resources/frontend/images/double.png") no-repeat;
        background-size: 100% 100%;
        padding-top: 5px;
    }
    .hiden{
        display: none;
    }
    .desc_container{padding: 0px;}
    .rule_title{
        height: 50px;
        line-height: 50px;
        background-color: #FED944;
        border-top-left-radius: 5px;
        border-top-right-radius: 5px;
        font-size: 1.7rem;
    }
    table{
        font-size: 1.6rem;
        border-collapse:separate;
        border-spacing:5px 25px;
        padding-left: 15px;
        padding-right: 15px;
    }
    table tr{padding: 10px 30px}
    .rule_item{
        padding: 2px 7px;
        margin: 5px;
        background-color: #FED944;
        font-size: 14px;
        margin-right: 15px;
    }
    .rule_iknow{
        height: 40px;
        font-size: 16px;
        margin-top: 30px;
        border-top: 1px solid #f6f6f6;
        line-height: 40px;
    }
    .no_redpack_res_title{
        height: 40px;
        text-align: center;
        background-color: #FED944;
        border-top-left-radius: 5px;
        border-top-right-radius: 5px;
        padding-top: 10px;
    }
    .no_redpack_res_body{
        padding: 40px 10px;
        font-size: 18px;
    }
    .rule_tips{
        font-size: 18px;
        padding-left: 8px;
        font-weight: 500;
    }
    .second_getredpack{
        display: block;
        margin: 15px auto;
        border: none;
        font-size: 16px;
        color: #fff;
        padding: 5px 8px;
        background-color: #FDCB2B;
    }
    .new_member_p{
        font-size: 18px;
        color: #ff6547;
    }
</style>

<script src="/resources/common/bootstrap-3.3.4/js/bootstrap.min.js"></script>
<div id="sub-modal" aria-hidden="true" data-backdrop="static" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content discount-setup" style="background-repeat: no-repeat; background-size: 100% 100%; background-image: url('/resources/frontend/images/red-bk.png'); width: 280px; min-height: 402px; margin: 50px auto;">
            <div id="jiantou" class="hidden" style="display: inline-block; overflow: hidden; background-repeat: no-repeat; background-size: 100% 100%; background-image: url('/resources/frontend/images/jt.png');"></div>
            <div id="text-des" style="font-size: 20px;">恭喜发财，大吉大利</div>
            <img id="sub-img" src="/resources/frontend/images/anniu.png" data-idmp="" />
            <button id="closedeliver" class="close sub-modal-close-btn" type="button">
                <img src="/resources/frontend/images/close-btn.png" style="width: 22px;" />
            </button>
        </div>
    </div>
</div>

<div id="sub-result-modal" aria-hidden="true" data-backdrop="static" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content discount-setup" style="background-repeat: no-repeat; background-size: 100% 100%; background-image: url('/resources/frontend/images/res-bkg.png'); width: 280px;min-height: 402px; margin: 50px auto;text-align: center;padding-bottom: 15px;">
            <img src="/resources/frontend/images/zlogo.png" style="width:55px;height: 55px;margin-top: 70px" alt="">
            <p class="sub-res-text" style="font-size: 16px;font-weight: bold;margin-top: 5px">摇钱吧</p>
            <p class="sub-res-text" style="font-size: 16px;color: #ADACAC;margin-top: 10px">恭喜发财，大吉大利</p>
            <p class="sub-res-text" style="font-size: 16px;color: #ADACAC; margin-top: 35px">恭喜您获得红包</p>
            <div class="old_member_div" style="font-size: 0px;color: #444; margin:8px auto;text-align: center; display: block;">
                <span id="discount-txt" style="font-weight: 700;font-size: 30px">0</span>
                <span style="font-size: 18px;">元</span>
            </div>
            <div class="new_member_div" style="font-size: 0px; color: #444; margin:5px auto;text-align: center; display: none;">
                <span id="second_discount-txt" style="font-weight: 700;font-size: 25px">0</span>
                <span style="font-size: 12px;">元</span>
                <p class="new_member_p" style="margin-bottom: 0px">您有新用户福利呦！</p>
                <button class="second_getredpack">再领一个</button>
            </div>
            <p class="sub-res-text hiden" style="font-size: 12px;color: red">已自动为您使用加一卡</p>
            <p class="sub-res-text" style="color: #A0A8B8;font-size: 10px;margin-top: 15px;">此红包下次可使用</p>

            <button id="closedeliver" class="close" type="button">
                <img src="/resources/frontend/images/close-btn.png" style="width: 22px" />
            </button>
        </div>
    </div>
</div>

<div id="sub-double-result-modal" aria-hidden="true" data-backdrop="static" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content discount-setup" style="background-repeat: no-repeat; background-size: 100% 100%; background-image: url('/resources/frontend/images/res-bkg.png'); width: 280px; height: 402px; margin: 50px auto;">
            <img src="/resources/frontend/images/zlogo.png" style="width:55px;height: 55px;margin-top: 70px" alt="">
            <p class="sub-res-text" style="font-size: 16px;font-weight: bold;margin-top: 5px">摇钱吧</p>
            <p class="sub-res-text" style="font-size: 16px;color: #ADACAC">恭喜发财，大吉大利</p>
            <p class="sub-res-text" style="font-size: 16px;color: #ADACAC; margin-top: 35px">恭喜您获得</p>
            <div style="color: #444;margin: 10px auto;text-align: center;">
                <div id="double-txt">
                    <p style="font-size: 12px">红包加一卡</p>
                    <p> + 1</p>
                </div>
            </div>
            <p class="sub-res-text" style="color: #A0A8B8; margin-top: 25px;font-size: 12px">下次红包自动加0.1元</p>
            <p class="sub-res-text" style="color: #A0A8B8; margin-top: 5px;font-size: 12px">每次限用一张</p>
            <button id="closedeliver" class="close" type="button">
                <img src="/resources/frontend/images/close-btn.png" style="width: 22px" />
            </button>
        </div>
    </div>
</div>

<div class="page-top" style="background-color: #ffd349; text-align: center; overflow: hidden; padding: 13px 0 8px 0;">
    <span>未使用红包</span>
    <h2 style="margin-top: 8px; font-size: 48px; color: #1b1b1b;">
        <?php echo $this->user->bonus; ?>
        <small style="font-size: 18px; color: #1b1b1b; line-height: 20px;">元</small>
    </h2>
</div>

<ul id="bonus-tab" class="nav nav-tabs" role="tablist" style="margin-bottom: 10px;">

    <li role="presentation" class="active" style="width: 33.3%;"><a href="#wrapper_trades" data-type="trades" aria-controls="wrapper_trade" role="tab" data-toggle="tab">交易记录</a></li>
    <li role="presentation" style="width: 33.3%;"><a href="#wrapper_gets" data-type="gets" aria-controls="wrapper_get" role="tab" data-toggle="tab">获得红包</a></li>
    <li role="presentation" style="width: 33.3%;"><a href="#wrapper_uses" data-type="uses" aria-controls="wrapper_use" role="tab" data-toggle="tab">使用红包</a></li>
</ul>

<div class="tab-content" style="overflow: hidden;">

    <div role="tabpanel" class="tab-pane active" id="wrapper_trades">
        <div class="content" id="iscroll_wrap_trade">
            <?php echo $this->renderPartial('bonushis_content', array(
                'data' => $trades,
                'type' => 'trades',
                'default_limit' => $default_limit,
                'desc'=>$top_desc['trades_desc']
            )); ?>
        </div>
    </div>

    <div role="tabpanel" class="tab-pane" id="wrapper_gets">
        <div class="content" id="iscroll_wrap_get">
            <?php echo $this->renderPartial('bonushis_content', array(
                'data' => $gets,
                'type' => 'gets',
                'default_limit' => $default_limit,
                'desc'=>$top_desc['gets_desc'],
            )); ?>
        </div>
    </div>

    <div role="tabpanel" class="tab-pane" id="wrapper_uses">
        <div class="content"  id="iscroll_wrap_use">
            <?php echo $this->renderPartial('bonushis_content', array(
                'data' => $uses,
                'type' => 'uses',
                'default_limit' => $default_limit,
                'desc'=>$top_desc['uses_desc']
            )); ?>
        </div>
    </div>
</div>

<?php $this->renderPartial('/template/payLoading')?>
<script>
    var trans_url = '/pay/getApiData',
        click_obj='',
        show_flag = false,
        click_btn = '',
        id_tradedetail='',
        status='',
        qrcodeurl='',
        idmp='',
        id_merchant='',
        idmpinforecord = '',
        requestNo=1;

    function getIsDiscount(id_tradedetail,id_merchant) {
        window.timer = setInterval(function(){
            if(show_flag){
                return ;
            }
            $.ajax({
                type: 'POST',
                url: trans_url,
                data: {
                    idTradeDetail: id_tradedetail,
                    idWxuser: '<?php echo $wxuser->id_wxuser; ?>',
                    openid: '<?php echo $wxuser->openid; ?>',
                    unionId: '<?php echo $wxuser->unionid; ?>',
                    idMerchant: id_merchant,
                    requestNo:requestNo,
                    nickname: '<?php echo $wxuser->nickname_encode; ?>',
                    headImgUrl: '<?php echo $wxuser->avatar_url; ?>',
                    language: '<?php echo $wxuser->language; ?>',
                    province: '<?php echo base64_encode($wxuser->province); ?>',
                    country: '<?php echo base64_encode($wxuser->country); ?>',
                    city: '<?php echo base64_encode($wxuser->city); ?>',
                    sex: parseInt('<?php echo $wxuser->gender; ?>'),
                    idmp: $('#sub-modal #sub-img').attr('data-idmp'),
                    entryIdWxplatform: '<?php echo $wxuser->id_wxplatform ?>',
                    idmpinforecord:idmpinforecord,
                    type:'get',
                    api_url:"<?= app()->params['get_isdiscount']?>",
                    api_type:'get_isdiscount',
                    api_place: 'bonushis'
                },
                json: "callback",
                jsonCallback:"isDiscountHandler",
                dataType: "json",
                success: function(data){
                    if(data.api_result == 200){

                        if(data.isdiscount){
                            if(show_flag){
                                return ;
                            }
                            clearInterval(window.timer);

                            var rep_discount = data.discount*1;
                            show_flag = true;

                            if(data.idWxuserDouble != ''){
                                $('.sub-res-text.hiden').css('display','block');
                            }else{
                                $('.sub-res-text.hiden').css('display','none');
                            }

                            if(idmp == "<?php echo app()->params['main_mapinfo_id']?>"){
                                requestNo = 2;
                                $('#second_discount-txt').text(rep_discount.toFixed(2));
                                $('.old_member_div').css('display', 'none');
                                $('.new_member_div').css('display', 'block');
                            }else{
                                requestNo = 1;
                                $('#discount-txt').text(rep_discount.toFixed(2));
                                $('.old_member_div').css('display', 'block');
                                $('.new_member_div').css('display', 'none');
                            }

                            $('#sub-modal').modal('hide');
                            $('#sub-result-modal').modal('show');
                            $('#sub-img').removeClass('qrcode');
                            $(click_obj).parent('span').text('已领取');
                            $(click_obj).remove();
                            if(click_btn != ''){
                                $(click_btn).removeClass('already_click');
                            }
                        }
                    }
                },
            });
        },2000)
    }

    function getPrize(id_tradedetail) {
        $.ajax({
            type: 'POST',
            url: '/pay/getprize',
            data: {
                id_tradedetail: id_tradedetail,
                id_wxuser: '<?php echo $this->user->id_wxuser; ?>'
            },
            dataType: "json",
            success: function(data){

                if(data.code == 200){
                    setTimeout(function () {
                        $('#sub-img').removeClass('rotate');
                        $('#sub-double-result-modal').modal('show');
                        $(click_obj).parent('span').text('已领取');
                        $(click_obj).remove();
                        $(click_btn).removeClass('already_click');
                    },500);
                    $('#sub-modal').modal('hide');
                }
            },
            error:function(){
                $('#sub-modal').modal('hide');
            }
        });
    }

    function getRedPack(obj,_id_tradedetail,merchant) {

        if(window.timer != ''){
            clearInterval(window.timer);
        }
        if(click_btn != ''){
            $(click_btn).removeClass('already_click');
        }

        click_obj = obj;
        id_tradedetail = _id_tradedetail;

        id_merchant = merchant;
        if($(click_obj).hasClass('loadding')){
            return false;
        }

        $('#text-des').html('恭喜发财，大吉大利');

        $('.get_discount_botton').addClass('loadding');
        $(click_obj).addClass('loadding');

        if($('.spinner').css("display") === 'none'){
            easyloading('show');
        }

        $.ajax({
            type: 'POST',
            url: trans_url,
            data: {
                idTradeDetail: id_tradedetail,
                idMerchant: id_merchant,
                idWxuser: '<?php echo $wxuser->id_wxuser; ?>',
                nickname: '<?php echo $wxuser->nickname_encode; ?>',
                headImgUrl: '<?php echo $wxuser->avatar_url; ?>',
                openid: '<?php echo $wxuser->openid; ?>',
                requestNo:requestNo,
                unionId: '<?php echo $wxuser->unionid; ?>',
                language: '<?php echo $wxuser->language; ?>',
                province: '<?php echo base64_encode($wxuser->province); ?>',
                country: '<?php echo base64_encode($wxuser->country); ?>',
                city: '<?php echo base64_encode($wxuser->city); ?>',
                sex: parseInt('<?php echo $wxuser->gender; ?>'),
                type:'get',
                api_url:"<?= app()->params['get_qrcode']?>",
                api_type:'get_qrcode',
                api_place: 'bonushis'
            },
            dataType: "json",
            success: function(data){
                easyloading('hide');
                setTimeout(function () {
                    $(click_obj).removeClass('loadding');
                    $('.get_discount_botton').removeClass('loadding');
                }, 1000);

                if(data.api_result == 200){
                    //showMsg('亲!稍等,马上天降红包哦',{position:'center'});

                    if(data.status=='<?php echo TradeDetail::GET_REDPACK_TYPE1?>' || data.status=='<?php echo TradeDetail::GET_REDPACK_TYPE5?>'){

                        $('#sub-modal #sub-img').css({"width": "100px","height": "100px",'margin-left': '-50px','top': '220px'}).attr({src: '/resources/frontend/images/anniu.png', 'data-idmp': ''});
                        $('#sub-img').removeClass('change-code');
                        $('#jiantou').addClass('hidden');
                        $('#sub-modal').modal('show');

                        status = data.status;
                        if(data.status == '<?php echo TradeDetail::GET_REDPACK_TYPE1?>'){
                            qrcodeurl = data.qrcodeurl;
                            idmp = data.idmp;
                            idmpinforecord = data.idmpinforecord;
                            $.ajax({
                                url:'/pay/Deliverhis',
                                async:true,
                                type: 'post',
                                data:{'id_wxuser':"<?php echo $this->user->id_wxuser; ?>", 'idmp':idmp, 'action':"<?php echo MpDeliverHis::ACTION_OPEN?>", 'id_tradedetail':id_tradedetail},
                                success:function(){},
                                error:function(){},
                            });
                        }
                    } else if(data.status==2){
                        showMsg('亲，休息一小时再来呗',{position:'center'});

                    }else{
                        showMsg('今日手气不佳，明天再试',{position:'center'});
                    }
                }else{
                    showMsg('今日手气不佳，明天再试',{position:'center'});
                }

            },
            error:function(){
                $('#sub-modal').modal('hide');
            }
        });
    }

    $(function(){

        //再领取一次
        $('.second_getredpack').click(function(){
            var _this = this;
            requestNo = 2;
            if($(_this).hasClass('loadding')){
                return false;
            }
            $(_this).addClass('loadding');

            easyloading('show');
            $.ajax({
                type: 'POST',
                url: trans_url,
                data: {
                    idTradeDetail: id_tradedetail,
                    idMerchant: id_merchant,
                    idWxuser: '<?php echo $this->user->id_wxuser; ?>',
                    nickname: '<?php echo $this->user->nickname_encode; ?>',
                    headImgUrl: '<?php echo $this->user->avatar_url; ?>',
                    openid: '<?php echo $this->user->openid; ?>',
                    unionId: '<?php echo $this->user->unionid; ?>',
                    language: '<?php echo $this->user->language; ?>',
                    province: '<?php echo base64_encode($this->user->province); ?>',
                    country: '<?php echo base64_encode($this->user->country); ?>',
                    city: '<?php echo base64_encode($this->user->city); ?>',
                    sex: parseInt('<?php echo $this->user->gender; ?>'),
                    requestNo: requestNo,
                    type:'get',
                    api_url:"<?= app()->params['get_qrcode']?>",
                    api_type:'get_qrcode',
                    api_place: 'bonushis'
                },
                dataType: "json",
                success: function(data){

                    $('#sub-result-modal').modal('hide');
                    $('#sub-double-result-modal').modal('hide');
                    if(data.api_result == 200){

                        status = data.status;

                        $('#sub-modal #sub-img').css({"width": "100px","height": "100px",'margin-left': '-50px','top': '220px'}).attr({src: '/resources/frontend/images/anniu.png', 'data-idmp': ''});
                        if(data.status=='<?php echo TradeDetail::GET_REDPACK_TYPE1?>'){
                            if(data.status == '1'){
                                qrcodeurl = data.qrcodeurl;
                                idmp = data.idmp;

                                $.ajax({
                                    url:'/pay/Deliverhis',
                                    async:true,
                                    type: 'post',
                                    data:{'id_wxuser':"<?php echo $this->user->id_wxuser; ?>", 'idmp':idmp, 'action':"<?php echo MpDeliverHis::ACTION_OPEN?>", 'id_tradedetail':id_tradedetail},
                                    success:function(){},
                                    error:function(){},
                                });
                            }
                        }

                        $('#sub-img').removeClass('change-code');
                        $('#sub-img').removeClass('already_click');
                        $('#jiantou').addClass('hidden');
                        $('#sub-modal').modal('show');
                    }
                    easyloading('hide');
                },
                error:function(){
                    $(_this).removeClass('loadding');
                    easyloading('hide');
                    $('#sub-result-modal').modal('hide');
                    $('#sub-double-result-modal').modal('hide');
                    $('#sub-modal').modal('hide');
                }
            });
        });

        //点击开事件
        $('#sub-img').click(function(){
            click_btn = this;
            show_flag = false;

            if(window.timer != '' && !$('#sub-img').hasClass('qrcode')){
                clearInterval(window.timer);
            }
            if($(click_btn).hasClass('already_click')){
                return ;
            }

            $(click_btn).addClass('already_click');
            if(!$(click_btn).hasClass('change-code')) $(click_btn).addClass('rotate');
            $(click_btn).addClass('change-code');

            if(status==''){
                $(click_btn).removeClass('already_click');
                $('#sub-modal').modal('hide');
                $('#sub-img').removeClass('rotate');
                return ;
            }
            if(status == '<?php echo TradeDetail::GET_REDPACK_TYPE1?>' && qrcodeurl != '' && idmp != ''){
                setTimeout(function () {
                    $('#sub-img').removeClass('rotate');
                    $('#sub-img').addClass('qrcode');
                    $('#text-des').css('font-size', '20px').html('长按二维码，最高可<span class="rotate_span" style="font-weight: bold;">免单</span>哦');
                    $('#jiantou').removeClass('hidden');

                    $('#sub-modal #sub-img').css({'width':'130px','height':'130px','margin-left':'-65px','top':'215px'}).attr({
                        src: qrcodeurl,
                        'data-idmp': idmp
                    });
                    getIsDiscount(id_tradedetail,id_merchant);

                },800);
            }else {
                getPrize(id_tradedetail);
            }
        });

        //关闭弹窗
        $('.modal .close').on('click', function(){

            if($(this).hasClass('sub-modal-close-btn') && status == '<?php echo TradeDetail::GET_REDPACK_TYPE1?>' && qrcodeurl != '' && idmp != ''){

                $.ajax({
                    url:'/pay/Deliverhis',
                    async:true,
                    type: 'post',
                    data:{'id_wxuser':"<?php echo $this->user->id_wxuser; ?>", 'idmp':idmp, 'action':"<?php echo MpDeliverHis::ACTION_CLOSE?>", 'id_tradedetail':id_tradedetail},
                    success:function(){},
                    error:function(){},
                });

            }

            $(this).parents('.modal').modal('hide');
            if(click_obj != ''){
                $(click_obj).removeClass('loadding');
            }
            show_flag = false;
            if(window.timer != ''){
                clearInterval(window.timer);
            }
        });

        //计算waper高度
        var sum_height = document.body.offsetHeight;
        var page__top_height = $('.page-top').outerHeight(true);
        var page__tab_height = $('#bonus-tab').outerHeight(true);
        $('.content').height(sum_height-page__top_height-page__tab_height);
        var isscoll_obj = '';
        //判断是否能实例化
        $('#bonus-tab a').each(function (i,item) {

            if($('.bonus-list.'+$(item).data('type')+' .end').length ==0){
                $(item).data('can_issrroll',1);

            }else{
                $(item).data('can_issrroll',0);

            }
            if(i==0 &&  $(item).data('can_issrroll')){

                $(item).data('iscrollObj', new iScroll('iscroll_wrap_trade', {
                    onScrollMove:function(){
                        if (this.y<(this.maxScrollY)) {
                            console.log('onScrollMove1');
                            $('#iscroll_wrap_trade .pull_icon').addClass('flip');
                            $('#iscroll_wrap_trade .pull_icon').removeClass('loading');
                            $('#iscroll_wrap_trade .more span').text('释放加载...');
                        }else{
                            console.log('onScrollMove2');
                            $('#iscroll_wrap_trade .pull_icon').removeClass('flip loading');
                            $('#iscroll_wrap_trade .more span').text('上拉加载...')
                        }
                    },
                    onScrollEnd:function(){
                        console.log('onScrollEnd');
                        if ($('#iscroll_wrap_trade .pull_icon').hasClass('flip')) {
                            $('#iscroll_wrap_trade .pull_icon').addClass('loading');
                            $('#iscroll_wrap_trade .more span').text('加载中...');
                            pullUpAction($(item));
                        }

                    },
                    onRefresh:function(){
                        console.log('onRefresh');
                        $('.pull_icon').removeClass('flip');
                        $('.pull_icon').removeClass('loading');

                        $('.more span').text('上拉加载...');
                    }

                }));

                isscoll_obj = $(item).data('iscrollObj')
            }
        });


        $('#bonus-tab a').on('click', function(e) {
            e.preventDefault();
            $(this).tab('show');

            //type类型
            type = $(this).data('type');

            //销毁
            var iscrollWrap = $($(this).attr('href')).find('.content');
            var tab_a_obj = $(this);

            if($(this).data('can_issrroll')){
                $(this).data('iscrollObj', new iScroll(iscrollWrap.attr('id'), {
                    onScrollMove:function(){
                        if (this.y<(this.maxScrollY)) {
                            $('#'+iscrollWrap.attr('id')+' .pull_icon').addClass('flip');
                            $('#'+iscrollWrap.attr('id')+' .pull_icon').removeClass('loading');
                            $('#'+iscrollWrap.attr('id')+' .more span').text('释放加载...');
                        }else{
                            console.log('onScrollMove2');
                            $('#'+iscrollWrap.attr('id')+' .pull_icon').removeClass('flip loading');
                            $('#'+iscrollWrap.attr('id')+' .more span').text('上拉加载...')
                        }
                    },
                    onScrollEnd:function(){
                        console.log('onScrollEnd');
                        if ($('#'+iscrollWrap.attr('id')+' .pull_icon').hasClass('flip')) {
                            $('#'+iscrollWrap.attr('id')+' .pull_icon').addClass('loading');
                            $('#'+iscrollWrap.attr('id')+' .more span').text('加载中...');
                            pullUpAction(tab_a_obj);
                        }

                    },
                    onRefresh:function(){
                        console.log('onRefresh');
                        $('#'+iscrollWrap.attr('id')+' .pull_icon').removeClass('flip');
                        $('#'+iscrollWrap.attr('id')+' .pull_icon').removeClass('loading');

                        $('.more span').text('上拉加载...');
                    }

                }));

                isscoll_obj = $(this).data('iscrollObj')
            }
        });

        var trade_page = 0,use_page=0,get_page=0,type='trades',page = trade_page;
        function pullUpAction(obj){

            switch (type){
                case 'trades':
                    trade_page++;
                    page= trade_page;
                    break;
                case 'uses':
                    use_page++;
                    page= use_page;
                    break;
                case 'gets':
                    get_page++;
                    page= get_page;
                    break;
            }
            page++;
            $.ajax({
                url:'/pay/bonushis',
                type:'post',
                data:{'page':page,'type':type},

                success:function(data){

                    //已取所有记录
                    if($('.bonus-list.'+type+' .isend').length !=0 ) {
                        $(obj).data('can_issrroll',false);
                        $('#wrapper_'+$(obj).data('type')+' .more').remove();
                        isscoll_obj.refresh();
                    }else{
                        $('.bonus-list.'+type).append(data);
                        isscoll_obj.refresh();
                    }
                },
                error:function(err){
                    console.log('error');
                }
            });
        }

    });
</script>